//
//  SZFilmCriticController.m
//  KaiJing
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "SZFilmCriticController.h"
#import "PKRequestManager.h"
#import "CJFilmCriticModel.h"
#import "CJFilmCriticTableViewCell.h"
#import "CJPictorialCellWebViewViewController.h"
@interface SZFilmCriticController ()

@property (nonatomic, strong) NSMutableArray *sourceArray;


@end

@implementation SZFilmCriticController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    _sourceArray = [NSMutableArray array];
    
    [self requestData];
    
    self.tableView.rowHeight = 380;
}


- (void)requestData {
    
    
    [PKRequestManager requestWithUrlString:@"http://morguo.com/forum.php?mod=acinecism&androidflag=1&appfrom=ios&iosversion=3.13&page=1" parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        
        NSArray *array = dataDic[@"data"][@"list"];
        for (NSDictionary *dic in array) {
            CJFilmCriticModel *model = [[CJFilmCriticModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [_sourceArray addObject:model];
        }
        
        [self.tableView reloadData];
    } error:^(NSError *error) {
        
    }];
    
    
    
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _sourceArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *idenfitier = @"CJFilmCriticTableViewCell";
    CJFilmCriticTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idenfitier];
    if (cell == nil) {
        cell = [[CJFilmCriticTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:idenfitier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = _sourceArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CJFilmCriticModel *model = _sourceArray[indexPath.row];
    
    self.filmBlock(model.tid);
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CJFilmCriticModel *model = _sourceArray[indexPath.row];
    
    CGFloat height = [CJFilmCriticTableViewCell imageVHeightForModel:model];
    
    return height + 170;
    
    
}









@end
